﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SEO.Business;

public partial class KeywordsSEO : AdminPage
{
    /// <summary>
    /// ID
    /// </summary>
    protected int nID=0;

    protected int nMID = 0;

    /// <summary>
    /// 次数
    /// </summary>
    protected int CountIndex
    {
        get { return ViewState["CountIndex"] == null ?1 : Convert.ToInt32(ViewState["CountIndex"]); }
        set { ViewState["CountIndex"] = value; }
    }

    protected bool bStatus = false;
    protected int nNum = 1;
    protected string strDateTime = string.Empty;
    /// <summary>
    /// 查询关键字的具体收录情况
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Common.GetQueryValue("id", 0), out nID);
        int.TryParse(Common.GetQueryValue("mid", 0), out nMID);
        bool.TryParse(Common.GetQueryValue("status", 0), out bStatus);
        strDateTime = Common.GetQueryValue("date", 0);
        
        if (!Page.IsPostBack)
        {
            InitCount();
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.KeywordsSEO;
    }

    /// <summary>
    /// 绑定数量
    /// </summary>
    protected void InitCount()
    {
        if (bStatus)
        {
            if (string.IsNullOrEmpty(strDateTime))
                strDateTime = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime dBeginTime = Convert.ToDateTime(strDateTime);
            DataTable dtCount = new BisSysRunLog().GetAllList(dBeginTime, dBeginTime.AddDays(1));
            rptCount.DataSource = dtCount;
            rptCount.DataBind();
            dtCount.Dispose();
        }
        else
        {
            DataTable dtCount = new DataTable();
            dtCount.Columns.Add("RunIndex", typeof(Int32));
            DataRow dr=dtCount.NewRow();
            dr["RunIndex"]=1;
            dtCount.Rows.Add(dr);
            rptCount.DataSource = dtCount;
            rptCount.DataBind();
            dtCount.Dispose();
        }
    }

    /// <summary>
    /// 初始化数据
    /// </summary>
    protected void InitData()
    {
        if (string.IsNullOrEmpty(strDateTime))
            strDateTime = DateTime.Now.ToString("yyyy-MM-dd");
        DateTime dBeginTime=Convert.ToDateTime(strDateTime);
        DataTable dtWebSeo = new BisWebSEO().GetWebSEOListByDayIndex(nMID, nID,CountIndex, dBeginTime, dBeginTime.AddDays(1));
        if (dtWebSeo!=null&&dtWebSeo.Rows.Count > 0)
        {
             noData.Style["display"] = "none";
             ltlCount.Text = dtWebSeo.Rows.Count.ToString();
        }
        else
        {
           noData.Style["display"] = "block";
        }
        rptWebSEO.DataSource = dtWebSeo;
        rptWebSEO.DataBind();
        dtWebSeo.Dispose();
    }

    /// <summary>
    /// 列表绑定
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptCount_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "SetIndex")
        {
            CountIndex=Convert.ToInt32(e.CommandArgument.ToString());
            nNum = 1;
            InitCount();
            InitData();
        }
        
    }
}